import util from '@/libs/util';
import Cookies from 'js-cookie';
import CONSTANTS from '@/config/constants';
import getDate from '@/util/getDate.js';

export default {
    name: 'exportable-table',
    data () {
        return {
            columns: [
                {
                    title: '主题',
                    key: 'themeid',
                    render: (h, params) => { return h('div', {}, params.row.themeName); }
                }, {
                    title: '奖项',
                    key: 'diplomasid',
                    render: (h, params) => { return h('div', {}, params.row.dipName); }
                }, {
                    title: '申诉人',
                    key: 'diplomasid',
                    render: (h, params) => { return h('div', {}, params.row.memberName); }
                }, {
                    title: '申诉原因',
                    key: 'diplomasid',
                    render: (h, params) => { return h('div', {}, params.row.remark); }
                }, {
                    title: '申诉状态',
                    key: 'status',
                    render: (h, params) => {
                        let status = params.row.status;
                        let statusLabel = '';
                        if (status === '0') {
                            statusLabel = '待处理';
                        } else if (status === '1') {
                            statusLabel = '已处理';
                        } else if (status === '2') {
                            statusLabel = '已撤销';
                        }
                        return h('div', {}, statusLabel);
                    }
                }, {
                    title: '申诉材料',
                    key: 'upload',
                    render: (h, params) => {
                        if (params.row.upload) {
                            return h('a', {
                                attrs: {
                                    href: CONSTANTS.SERVER_HOST + params.row.upload,
                                    target: '_blank'
                                }
                            }, '查看');
                        }
                    }
                }, {
                    title: '申诉时间',
                    key: 'createtime',
                    render: (h, params) => { return h('div', {}, getDate.getDate(params.row.appealDate, 'time')); }
                },
                {title: '操作',
                    key: 'action',
                    width: 200,
                    align: 'center',
                    render: (h, params) => {
                        if (params.row.status === '2') {
                            return h('div', {}, '');
                        }
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.detailModal = true;
                                        util.ajax.post('/busine/prizes/appeal/detail', util.toFormData({
                                            id: params.row.id
                                        })).then(res => {
                                            this.formData = res.data.data;
                                        });
                                    }
                                }
                            }, '处理')
                        ]);
                    }
                }],
            baseuser: JSON.parse(Cookies.get('baseUser')),
            data: [],
            formData: {},
            query: {
                themeName: '',
                dipName: '',
                status: '0'
            },
            total: 0,
            pageIndex: 1,
            pageSize: 10,
            detailModal: false
        };
    },
    mounted () {
        this.loadList();
    },
    methods: {
        loadList () {
            util.ajax.post('/busine/prizes/appeal/list', util.toFormData({
                page: this.pageIndex,
                size: this.pageSize,
                themeName: this.query.themeName,
                dipName: this.query.dipName,
                status: this.query.status,
                orgId: this.baseuser.orgId
            })).then(res => {
                this.data = res.data.data.list;
                this.total = res.data.data.total;
            });
        },
        refresh () {
            this.query = {
                themeName: '',
                dipName: '',
                status: '0'
            };
            this.loadList();
        },
        save () {
            let formData = {};
            for (var key in this.formData) {
                formData[key] = this.formData[key];
            }
            formData.status = '1';
            util.ajax.post('/busine/prizes/appeal/update', util.toFormData(formData)).then(res => {
                this.detailModal = false;
                this.loadList();
            });
        }
    }
}